<template>
  <el-dialog
    title="新增工单"
    :visible.sync="dialogVisible"
    width="600px"
  >
    <el-form ref="userForm" label-width="150px" :model="form" :rules="rules">
      <!-- 姓名 部门 -->
      <el-row>
        <el-col :span="12">
          <el-form-item label="设备编号" prop="innerCode">
            <el-input v-model="form.innerCode" size="mini" class="inputW" @change="fn" />
          </el-form-item>
        </el-col>

      </el-row>
      <!-- 工号 入职时间 -->
      <el-row>
        <el-col :span="12">
          <el-form-item label="工单类型" prop="productType">
            <el-select v-model="form.productType" placeholder="请选择" class="inputW">
              <el-option
                v-for="item in options"
                :key="item.value"
                v-model="form.productType"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <!--手机 聘用形式  -->
      <el-row>
        <el-col :span="12">
          <el-form-item label="补货数量"><span class="cl" @click="lack">补货详情</span>
          </el-form-item></el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="运营人员" prop="userId">
            <el-select v-model="form.userId" placeholder="请选择" class="inputW">
              <el-option
                v-for="item in options1"
                :key="item.updateTime"
                v-model="form.userId"
                :label="item.userName"
                :value="item.userName"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="备注" prop="desc">
            <el-input
              v-model="form.desc"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4}"
              placeholder="请输入内容"
              class="inputW"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-dialog
      title="补货详情"
      :visible.sync="dialog"
      width="650px"
      :modal="a"
    >

      <el-table
        :data="list"
        style="width: 100%"
        height="380"
      >
        <el-table-column
          prop="channelCode"
          label="货到编号"
          width="92"
        />
        <el-table-column
          prop="sku.skuName"
          label="商品名称"
          width="92"
        />
        <el-table-column
          prop="currentCapacity"
          label="当前数量"
          width="92"
        />
        <el-table-column
          prop="maxCapacity"
          label="还可添加"
          width="92"
        />
        <el-table-column
          prop="price"
          label="补满数量"
        >
          <el-input-number v-model="num" controls-position="right" :min="1" :max="10" @change="handleChange" />
        </el-table-column>
      </el-table>

      <span slot="footer" class="dialog-footer">
        <div class="footer">
          <el-button class="cancel" @click="dialog = false">取 消</el-button>
          <el-button type="primary" class="confirm" @click="add">确 定</el-button>

        </div>
      </span>
    </el-dialog>

    <span slot="footer" class="dialog-footer">
      <div class="footer">
        <el-button class="cancel" @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" class="confirm" @click="submit">确 定</el-button>
      </div>
    </span>
  </el-dialog>
</template>

<script>
import { cancelList, workOrderDetail, getOperatorList } from '@/api/workOrder'
export default {
  name: 'WorkOrder',
  props: {
    detailId: {
      type: Number,
      default: null
    }
  },
  data () {
    return {
      num: 1,
      dialogVisible: false,
      dialog: false,
      a: false,
      form: {
        createType: 1,
        innerCode: '',
        userId: '',
        productType: '补货工单',
        desc: '',
        details: {
          channelCode: '',
          expectCapacity: '',
          skuId: '',
          skuName: '',
          skuImage: ''
        }

      },
      innerCode: '',
      rules: {
        innerCode: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        userId: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        productType: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        desc: [
          { required: true, message: '请输入', trigger: 'blur' }
        ]
      },
      options: [{
        value: '选项1',
        label: '补货工单'
      }],
      options1: [],
      list: []
    }
  },
  created () {
  },
  methods: {
    dialogVisibleOpen () {
      this.getTaskDetail()
      this.dialogVisible = true
    },
    async getTaskDetail () {
      console.log(this.detailId)
      const res = await workOrderDetail(this.detailId)
      this.innerCode = res.innerCode
      this.getOperatorLists()
      this.form = { ...res }
      console.log(res)
    },
    async getOperatorLists () {
      const res = await getOperatorList(this.innerCode)
      this.options1 = res
      console.log(res)
    },

    async submit () {
      this.fn()
      this.$refs.userForm.resetFields()
      const data = this.$refs.userForm.validate()
      if (data) {
        // await addList(this.form)
        this.$message.warning('演示系统，不支持此操作')
        this.dialogVisible = false
      }
    },

    async fn () {
      const data = await cancelList(this.innerCode)
      console.log(data)
      this.list = data
    },

    lack () {
      this.fn()
      this.dialog = true
    },
    handleChange (value) {
      console.log(value)
    },
    async  add () {
      this.dialog = false
    }
  }
}
</script>

<style scoped lang='scss'>
::v-deep .el-dialog {
  border-radius: 10px !important;
}
.footer {
  text-align: center;
}
.cancel {
  background-color: rgb(251, 244, 240) !important;
    color: rgb(101, 91, 86) !important;
    border: none;
}

.confirm {
  background: linear-gradient(135deg, rgb(255, 151, 67), rgb(255, 94, 32)) !important;
  border: none;
}
.edit-form {
      background: #fff;
    }
    .inputW {
        width: 360px;
      }

      .cl{
        font-size: 14px;
        color: #5f84ff;
      }
</style>
